# -*- coding: gbk -*-
import os, sys, time

class Log:
    def __init__(self, path):
        f = open(path, 'w')
        f.close()        
        self.__file = open(path, 'a')

    def handler(self):
        return self.__file

    def close(self):
        self.__file.close()
    
    def info(self, msg):
        time0 = time.strftime('%Y-%m-%d', time.localtime(time.time())) 
        time1 = time.strftime('%H:%M:%S', time.localtime(time.time()))
        line = '%s %s  INFO: %s' % (time0, time1, msg)
        print line
        self.__file.write(line + '\n')
        self.__file.flush()

    def debug(self, msg):
        time0 = time.strftime('%Y-%m-%d', time.localtime(time.time())) 
        time1 = time.strftime('%H:%M:%S', time.localtime(time.time()))
        line = '%s %s  DEBUG: %s' % (time0, time1, msg)
        print line
        self.__file.write(line + '\n')
        self.__file.flush()
    
    def warn(self, msg):
        time0 = time.strftime('%Y-%m-%d', time.localtime(time.time())) 
        time1 = time.strftime('%H:%M:%S', time.localtime(time.time()))
        line = '%s %s  WARNING: %s' % (time0, time1, msg)
        print line
        self.__file.write(line + '\n')
        self.__file.flush()
    
    def error(self, msg):
        time0 = time.strftime('%Y-%m-%d', time.localtime(time.time())) 
        time1 = time.strftime('%H:%M:%S', time.localtime(time.time()))
        line = '%s %s  ERROR: %s' % (time0, time1, msg)
        print line
        self.__file.write(line + '\n')
        self.__file.flush()


global inst
global loggerFile, requestLogFile, logdir
logdir = os.path.split(os.path.realpath(__file__))[0]
inst = None
